//
//  WPCoinTopUpCVC.m
//  wobingwoyi
//
//  Created by WGP on 16/8/29.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPCoinTopUpCVC.h"

@interface WPCoinTopUpCVC ()

@end
@implementation WPCoinTopUpCVC

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self bgbtn];
    [self priceLabel];
    [self descriptionLabel];
}

-(UIButton *)bgbtn
{
    if (_bgbtn == nil)
    {
        _bgbtn = [WPBtnNoHighLight buttonWithType:UIButtonTypeCustom];
        [_bgbtn setBackgroundImage:[UIImage imageNamed:@"coin_normal"] forState:UIControlStateNormal];
        [_bgbtn setBackgroundImage:[UIImage imageNamed:@"coin_selected"] forState:UIControlStateSelected];
        [_bgbtn addTarget:self action:@selector(bgBtnDidClick:) forControlEvents:UIControlEventTouchDown];
        [self.contentView addSubview:_bgbtn];
        
        [_bgbtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
    }
    return _bgbtn;
}

-(UILabel *)priceLabel
{
    if (_priceLabel == nil)
    {
        _priceLabel = [UILabel new];
        _priceLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_priceLabel];
        
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(10);
        }];
    }
    return _priceLabel;
}

-(UILabel *)descriptionLabel
{
    if (_descriptionLabel == nil)
    {
        _descriptionLabel = [UILabel new];
        _descriptionLabel.font = [UIFont systemFontOfSize:11];
        _descriptionLabel.textColor = RGB_SAME(153);
        [self.contentView addSubview:_descriptionLabel];
        
        [_descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.top.equalTo(self.priceLabel.mas_bottom).offset(8);
        }];
    }
    return _descriptionLabel;
}

-(void)setProduct:(SKProduct *)product
{
    _product = product;
    self.priceLabel.text = [NSString stringWithFormat:@"%@元",product.price];
    self.descriptionLabel.text = product.localizedTitle;
    
}

-(void)bgBtnDidClick:(WPBtnNoHighLight *)btn
{
    if (self.bgBtnDidClick)
    {
        self.bgBtnDidClick(btn);
    }
}

@end
